package com.example.peibei.ui.activity;

import android.content.Intent;
import android.os.Bundle;

import com.dingtao.common.core.DataCall;
import com.dingtao.common.core.WDActivity;
import com.dingtao.common.core.exception.ApiException;
import com.dingtao.common.util.SPUtils;
import com.dingtao.common.util.UIUtils;
import com.example.peibei.R;
import com.example.peibei.base.SpConstant;
import com.example.peibei.service.presenter.ChangePhonePresenter;
import com.example.peibei.ui.weight.CEditText;

import butterknife.BindView;
import butterknife.OnClick;

public class GetSmsActivity extends WDActivity {
    @BindView(R.id.cedittext)
    CEditText cedittext;
    private String phone;
    private SPUtils spUtils;
    private String token;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_get_sms;
    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        phone = intent.getStringExtra("phone");
        spUtils = new SPUtils(GetSmsActivity.this, SpConstant.USER_TOKEN);
        token = spUtils.getString(SpConstant.USER_TOKEN);
        ChangePhonePresenter changePhonePresenter = new ChangePhonePresenter(new SetPhoneCall());
        cedittext.setOnFinishListener(new CEditText.OnFinishListener() {
            @Override
            public void onFinish(String msg) {
                changePhonePresenter.reqeust("Bearer " + token, msg, phone);
            }
        });
    }

    @OnClick(R.id.iv_back)
    public void back() {
        finish();
    }

    @OnClick(R.id.tv_send_sms)
    public void sendSms() {

    }

    class SetPhoneCall implements DataCall<String> {

        @Override
        public void success(String data, Object... args) {
            UIUtils.showToastSafe("设置手机号成功");
            finish();
        }

        @Override
        public void fail(ApiException e, Object... args) {
            UIUtils.showToastSafe("设置失败：" + e.getDisplayMessage());
        }
    }

    @Override
    protected void destoryData() {

    }
}
